//
//  YFBrowseRecordCell.m
//  QuanJieShopProject
//
//  Created by apple on 2018/5/25.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFBrowseRecordCell.h"
@interface YFBrowseRecordCell ()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@end

@implementation YFBrowseRecordCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"YFBrowseRecordCellID";
    YFBrowseRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[YFBrowseRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self makeView];
    }
    return self;
}

- (void)makeView {
    
    // 图片
    UIImageView *imgView = [[UIImageView alloc] init];
    imgView.image = [UIImage imageNamed:@"noImage"];
    [self addSubview:imgView];
    self.imgView = imgView;
    
    // 名字
    UILabel *nameLabel = [[UILabel alloc] init];
//    nameLabel.text = @"¥1222.22";
    nameLabel.textColor = [UIColor colorWithHexString:@"333333"];
    nameLabel.font = [UIFont systemFontOfSize:16];
    nameLabel.numberOfLines = 2;
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    // 价格
    UILabel *priceLabel = [[UILabel alloc] init];
//    priceLabel.text = @"¥1222.22";
    priceLabel.textColor = [UIColor colorWithHexString:@"ff3400"];
    priceLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(self).with.offset(10);
        make.bottom.equalTo(self).with.offset(-10);
        make.width.equalTo(self.imgView.mas_height);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).with.offset(10);
        make.right.equalTo(self.mas_right).with.offset(-10);
        make.top.equalTo(self).with.offset(10);
        make.height.equalTo(@(40));
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).with.offset(10);
        make.right.equalTo(self.mas_right).with.offset(-10);
        make.top.equalTo(self.nameLabel.mas_bottom).with.offset(10);
        make.height.equalTo(@(20));
    }];
}


- (void)setModel:(YFBrowseRecordModel *)model {
    _model = model;

    self.nameLabel.text = model.goods_name;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@", model.shop_price];
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.original_img]] placeholderImage:[UIImage imageNamed:@"noImage"]];

}
@end
